# @Author   : tan90
# @Time     : 2025/3/17 10:57
from tkinter import *
from tkinter import messagebox

app = Tk()


# 设置窗口大小和位置
def cal_geometry(tk: Tk):
    max_size = tk.maxsize()
    print(f"屏幕分辨率 {max_size}")
    w = int(max_size[0] / 2)
    h = int(max_size[1] / 2)
    left = int((max_size[0] - w) / 2)
    top = int((max_size[1] - h) / 2)
    return f"{w}x{h}+{left}+{top}"


def close():
    print("关闭窗口")
    res = messagebox.askokcancel("提示", "确定要关闭吗？")
    if res:
        app.destroy()


app.resizable(True, True)
app.iconbitmap("favicon.ico")
app.geometry(cal_geometry(app))
app.protocol("WM_DELETE_WINDOW", close)

app.title("我的第一个GUI程序")

label1 = Label(app, text="标签1")
label1.pack()


def btn01_click():
    print("btn01 clicked")
    messagebox.showinfo("提示框", "hello world!!!")


btn01 = Button(app, command=btn01_click, text="发送")
btn01.pack()

app.mainloop()
